/**
 * @(#) NoticeViewProxy.as
 *
 * @date		2010. 11. 01.
 * @version		2.0
 * @author		Shin, Yunwoo
 * @client		Service Ace
  * @module		notice (공지사항 관리)
 * @description	공지사항 상세 내용 - Proxy
 * 				 
 */
package com.skt.common_hr.schoolexp.model
{
	import com.skt.common_hr.common.puremvc.CommonProxy;
	import com.skt.common_hr.schoolexp.model.vo.SchoolExpListVO;
	import com.wcl.utils.DateUtil;
	
	import mx.collections.ArrayCollection;
	import mx.rpc.events.FaultEvent;
	import mx.rpc.events.ResultEvent;

	public class SchoolExpListProxy extends CommonProxy
	{
		public static const NAME:String = "SchoolExpListProxy";
		
		public static const LOAD_SCHOOLEXP_LIST_COMPLETE:String = "loadSchoolExpListComplete";
		public static const LOAD_SCHOOLEXP_LIST_FAILED:String = "loadSchoolExpListFailed";

		public var schoolExpList:ArrayCollection;


		/**
		 * 생성자
		 * 
		 * @param
		 * @return void
		 */
		public function SchoolExpListProxy(data:Object=null)
		{
			super(NAME, data);
		}
		
		
		/**
		 * data load를 수행
		 * 		- DataLoader 를 생성하고 Import Parameter 객체를 생성, RFC를 호출
		 * 
		 * @param pernr 사번
		 * @return void
		 */
		public function load(pernr:String, year:String):void
		{
			var param:Object = new Object();
			param["I_PERNR"] = pernr;
			param["I_YEAR"] = year;

			loadData("ZD_HR_0152", param, result, fault); 
		}
		
		
		///////////////////////////////////////////////////////////////////////////////////////////////////
		//
		//	Event Listeners
		//
		///////////////////////////////////////////////////////////////////////////////////////////////////
		
		
		/**
		 * 서버에서 정상적으로 리턴된 결과를 처리
		 * 
		 * @param
		 * @return void
		 */
		public function result(event:ResultEvent):void
		{
			if(retCode==0) {
				schoolExpList = parseList(event.result.OTAB);
				facade.sendNotification(LOAD_SCHOOLEXP_LIST_COMPLETE, this);
			}
			else {
				facade.sendNotification(LOAD_SCHOOLEXP_LIST_FAILED, this);
			}
		}
		
		/**
		 * 서버에서 오류가 발생했을 처리
		 * 
		 * @param
		 * @return void
		 */
		private function fault(event:FaultEvent):void
		{
			facade.sendNotification(LOAD_SCHOOLEXP_LIST_FAILED, this);
		}
		
		
		
		
		///////////////////////////////////////////////////////////////////////////////////////////////////
		//
		//	Data Parsing functions
		//
		///////////////////////////////////////////////////////////////////////////////////////////////////
		/**
		 * 서버에서 전달된 result 객체를 분석하여 Value Object를 생성
		 * 
		 * @param
		 * @return 공지사항 Value Object
		 */
		 private function parseList(src:ArrayCollection):ArrayCollection
		{
			var list:ArrayCollection = new ArrayCollection;
			
			for(var i:int = 0; i < src.length; i++)
			{
				var vo:SchoolExpListVO = new SchoolExpListVO();
				
				vo.WEL_KEY01	= src[i].WEL_KEY01;							// 
				vo.WSTATUS		= src[i].WSTATUS;							// 
				vo.WTEXT		= src[i].WTEXT;							// 
				vo.BEGDA		= DateUtil.stringToDateTime(src[i].BEGDA);	// 
				vo.TOTPY		= src[i].TOTPY * 100;								//신청금액
				vo.ZPAYDT		= DateUtil.stringToDateTime(src[i].ZPAYDT);	//지급일
				vo.TOTPY2		= src[i].TOTPY2 * 100;							//지급금액
				vo.SLART		= src[i].SLART;								//학교구분
				vo.ZSLART		= src[i].ZSLART;							//학교명
				vo.FAMSA		= src[i].FAMSA;								//가족관계
				vo.FCNAM		= src[i].FCNAM;								//가족이름
				vo.ZGRADE		= src[i].ZGRADE;							//학년

				list.addItem(vo);
			}
			
			return list;
		}
	}
}